-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Private API for RefreshMemoryLimit #83707
Conversation
Tagging subscribers to this area: @dotnet/gc Issue Detailsnull
|
16fa862
to
dabc733
Compare
f1157dd
to
e14399a
Compare
e14399a
to
a69812c
Compare
2204863
to
da4609e
Compare
c47c5b8
to
c365c40
Compare
Here is the validation done for the PR.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
c365c40
to
9f7f5cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
other than the last couple of comments, this LGTM!
This PR implements #70601 as a private method, we wanted to do that as a private method and get it merged to facilitate testing on a broader scale while not committing to a particular API shape for everyone just yet. For scoping reasons, this is currently only tested for Windows x64, it should work on Windows x86 with a caveat that we will not establish a heap hard limit if we don't already have one. Any other platforms are not tested yet.
Before this change, we detect the physical memory (as well as the additional limits such as job objects) and configure the GC, and then we never change it. Some of these configurations are just some numeric fields on the
gc_heap
class, while some others are structural (e.g. number of heaps, region_range, etc ...).This change aims at providing some flexibility on top of that init-once theme above. In particular, we allow the memory limit to change while the process is still running. It would be difficult to make structural changes, but it is relatively easy to just alter some numerical values. This change does just that. It factors out the memory-related settings into a separate function and allows them to be re-computed when the memory limit changes and the GC is notified through the
RefreshMemoryLimit
API call.The technical challenge is commit accounting. If we happen to have no job object applied on the process and then one is applied later, now we have to set the
heap_hard_limit
, but then how would we know how much we already committed? The bulk of therefresh_memory_limit
handles that by walking through thegc_heap
data structure and figuring that out.To make sure that is correct, a debug-only mode
COMMITTED_BYTES_SHADOW
is introduced. This mode will maintain the committed bytes all the time regardless of the existence of theheap_hard_limit
, then we can assert the reconstructed value through the heap walking is producing the correct value as if we were tracking it all the time. This committed byte reconstruction and the testing knob will also be useful for other heap restructuring purposes.